﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using W.Common.Enum;
using W.Purchase.Domain.DTO;
using W.Purchase.Domain.PageDTO;
using W.Purchase.Read.API.AppLication.Command.ProcurementCommands;

namespace W.Purchase.Read.API.Controllers
{
    /// <summary>
    /// 采购管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProcurementsController : ControllerBase
    {
        private readonly IMediator _mediator;
        public ProcurementsController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 显示采购表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProcurementPageDTO>> ShowProcurement([FromQuery]ProcurementSelectCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 采购状态类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public dynamic GetProcurementState()
        {
            return Enum.GetValues(typeof(ProcurementState))
                .Cast<ProcurementState>()
                .Select(x => new
                {
                    Value = (int)x,
                    Text = x.ToString()
                }).ToList();
        }
        /// <summary>
        /// 反填采购表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProcurementFanDTO>> FanProcurement([FromQuery]ProcurementFanCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 采购退货表显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProcurementPageDTO>> ReturnProcurement([FromQuery] ReturnSelectCommands command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 反填采购退货表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ProcurementFanDTO>> FanReturn([FromQuery] ReturnFanCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
